package com.example.onlineeducation.repository

import com.example.onlineeducation.data.json.HotSearchJson
import com.example.onlineeducation.mapper.CertificateListMapper
import com.example.onlineeducation.mapper.RegisterSearchGroupMapper
import com.example.onlineeducation.mapper.RegisterSearchProjectMapper
import com.example.onlineeducation.mapper.RegisterSearchWorkTypeMapper

import com.example.onlineeducation.net.ApiService
import com.yc.jetpacklib.base.YcRepository
import com.yc.jetpacklib.extension.ycFlow
import com.yc.jetpacklib.net.YcResult
import com.yc.jetpacklib.recycleView.YcPager
import kotlinx.coroutines.flow.Flow
import pageListToDataSource

/**
 * SimpleDes:
 * Creator: Sindi
 * Date: 2021-06-30
 * UseDes:首页
 */
class SearchRepository(private val apiService: ApiService) : YcRepository() {

    /**
     * 获取热门搜索
     */
    fun getHotSearch(): Flow<YcResult<List<HotSearchJson>?>> = ycFlow {
        val json = apiService.getHotSearch().dataList
        send(YcResult.Success(json))
    }

    /**
     * 获取项目列表
     */
    private val mRegisterSearchProjectMapper by lazy {
        RegisterSearchProjectMapper()
    }

    fun getProList(proName: String) = YcPager.getPagerFlow { pageIndex, pageSize ->
        apiService.getProList(proName, pageIndex, pageSize).pageListToDataSource(mRegisterSearchProjectMapper)
    }

    /**
     * 获取班组列表
     */
    private val mRegisterSearchGroupMapper by lazy {
        RegisterSearchGroupMapper()
    }

    fun getGroupList(projId: String,proName: String) = YcPager.getPagerFlow { pageIndex, pageSize ->
        apiService.getGroupList(proName,projId, pageIndex, pageSize).pageListToDataSource(mRegisterSearchGroupMapper)
    }

    /**
     * 获取工种列表
     */
    private val mRegisterSearchWorkTypeMapper by lazy {
        RegisterSearchWorkTypeMapper()
    }

    fun getWorkTypeList(workTypeName: String) = YcPager.getPagerFlow { pageIndex, pageSize ->
        apiService.getWorkTypeList(workTypeName, pageIndex, pageSize).pageListToDataSource(mRegisterSearchWorkTypeMapper)
    }

}